layui.use(['form','jquery','jquery_cookie'],
    function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            $ = layui.jquery_cookie($);
        //监听提交
        form.on('submit(saveBtn)',function (data) {
            //所有表单元素的值
            console.log(data.field);

            $.ajax({
                type:"post",
                url:ctx+"/user/updatePwd",
                data:{
                    oldPassword:data.field.old_password,
                    newPassword:data.field.new_password,
                    repeatPassword:data.field.again_password
                },
                success:function (result) {
                    //判断是否修改成功
                    if (result.code == 200) {
                        //修改密码后，清空cookie数据，跳转到登录页面
                        layer.msg("用户密码修改成功，系统将在3秒后退出...",function () {
                            //清空cookie
                            $.removeCookie("userIdStr",{domain:"localhost",path:"/crm"});
                            $.removeCookie("userName",{domain:"localhost",path:"/crm"});
                            $.removeCookie("trueName",{domain:"localhost",path:"/crm"});
                            //跳转到登录页面(父窗口跳转)
                            window.parent.location.href = ctx + "/index";
                        })
                    } else {
                        layer.msg(result.msg,{icon:5});
                    }
                }
            })
        });
    });